class DataRecovery {
    _recordData = () => { }
    _recoveryData = () => { }
    constructor(recordData = () => { }, recoveryData = (data) => { }) {
        this._recordData = () => {
            recordData()
        }
        this._recoveryData = recoveryData
    }
    dataHistory = []
    record() {
        let id = 1
        if (this.dataHistory.length) {
            id = this.dataHistory[this.dataHistory.length - 1].id + 1
        }
        this.dataHistory.push({
            id,
            data: JSON.stringify(this._recordData())
        })
        return id
    }
    recovery(id) {
        for (let i = 0; i < this.dataHistory.length; i++) {
            if (this.dataHistory[i].id == id) {
                this._recoveryData(JSON.parse(this.dataHistory[i].data))
                return
            }
        }
        console.log('未能还原数据')
    }
}

export default DataRecovery